var MyTechRiderApp = angular.module('MyTechRiderApp', ['ngResource', 'ngRoute', 'myTechRiderControllers']);

var MyTechRiderControllers = angular.module('myTechRiderControllers', []);

MyTechRiderApp.config(['$routeProvider',
function($routeProvider) {
	$routeProvider.when('/home', {
		templateUrl : 'templates/home-tmp.html',
		controller : 'HomeController'
	}).when('/', {
		templateUrl : 'templates/home-tmp.html',
		controller : 'HomeController'
	}).when('/artist-info', {
		templateUrl : 'templates/artist-info-tmp.html',
		controller : 'ArtistInfoController'
	}).when('/stage', {
		templateUrl : 'templates/stage-tmp.html',
		controller : 'StageController'
	}).when('/back-line', {
		templateUrl : 'templates/back-line-tmp.html',
		controller : 'BackLineController'
	}).when('/pa', {
		templateUrl : 'templates/pa-tmp.html',
		controller : 'PaController'
	}).when('/foh', {
		templateUrl : 'templates/foh-tmp.html',
		controller : 'FohController'
	}).when('/monitors', {
		templateUrl : 'templates/monitors-tmp.html',
		controller : 'MonitorsController'
	}).when('/voice', {
		templateUrl : 'templates/voice-tmp.html',
		controller : 'VoiceController'
	}).when('/acustic-guitar', {
		templateUrl : 'templates/acustic-guitar-tmp.html',
		controller : 'AcusticGuitarController'
	}).when('/electric-guitar', {
		templateUrl : 'templates/electric-guitar-tmp.html',
		controller : 'ElectricGuitarController'
	}).when('/drum', {
		templateUrl : 'templates/drum-tmp.html',
		controller : 'DrumController'
	}).when('/bass', {
		templateUrl : 'templates/bass-tmp.html',
		controller : 'BassController'
	}).when('/piano', {
		templateUrl : 'templates/piano-tmp.html',
		controller : 'PianoController'
	}).when('/keyboard', {
		templateUrl : 'templates/keyboard-tmp.html',
		controller : 'KeyboardController'
	}).when('/input-list', {
		templateUrl : 'templates/input-list-tmp.html',
		controller : 'InputListController'
	}).when('/creditos', {
		templateUrl : 'templates/creditos-tmp.html',
		controller : 'CreditosController'
	}).when('/plantillas-cargadas', {
		templateUrl : 'templates/plantillas-cargadas-tmp.html',
		controller : 'TemplatesController'
	}).otherwise({
		redirectTo : '/home'
	});
}]);

MyTechRiderApp.controller('HomeController', function($scope, $http, $rootScope) {

	$http.get('data/MyRiderOptions.json').success(function(data) {
		$rootScope.RiderConfigData = data;
	});
	
	function getAvailableChannels() {
		var listChannels = [];
		angular.forEach($rootScope.backstage.channels, function(value, key) {
			console.log(key);
		});

		return listChannels;
	}

});

MyTechRiderApp.controller('GeneralController', function($scope, $rootScope) {

	$rootScope.backstage = {

	};


	$rootScope.backstage.positions = [];
	$rootScope.backstage.acusticGuitar = [];
	$rootScope.backstage.electricGuitar = [];
	$rootScope.backstage.voice = [];
	$rootScope.backstage.drum = [];
	$rootScope.backstage.bass = [];
	$rootScope.backstage.piano = [];
	$rootScope.backstage.keyboard = [];
	$rootScope.backstage.channels = [];
	$rootScope.auxMonitor = [];

	var listAvailableChannels = [],j = 0;

	for (var i = 1; i <= 32; i++) {
		$rootScope.backstage.channels[i - 1] = {
			"channel" : i
		};

		listAvailableChannels[i-1] = {
			"channel" : i
		};
	}

	$scope.change = function(pAction) {

		if (pAction === "add") {
			j++;
		} else {
			j--;
		}
		$scope.channel = listAvailableChannels[j].channel;
	};
	$scope.updateDataListChannel = function (event){
		var lengthArr = listAvailableChannels.length;
		var lastDataPos = listAvailableChannels[lengthArr-1];
		
		listAvailableChannels[j] = lastDataPos;
		listAvailableChannels.pop();
		listAvailableChannels.sort(function (a, b) { 
		    return a.channel - b.channel;
		});

		$rootScope.getFirstAvailableChannel();
	}
	$rootScope.getFirstAvailableChannel = function(){
		$scope.channel = listAvailableChannels[0].channel;
		return 	$scope.channel;
	}

	$scope.getListAvailableChannels = function(){
		return listAvailableChannels;
	}
});


MyTechRiderApp.controller('ArtistInfoController', function($scope, $rootScope) {
	var dataArtist = [];
	$scope.save = function() {
		var i = 0;
		angular.forEach($scope.artist, function(value, key) {
			if (i === 0) {
				dataArtist.push({
					bandName : value.name
				});

			} else {
				dataArtist.push({
					artistName : value.musico,
					artistRol : value.rol,
					artistId : value.id,
					artistPhone : value.phone,
					artistEmail : value.email
				});
			}
			i++;
		});
		$rootScope.dataArtist = dataArtist;
	};

});

MyTechRiderApp.controller('StageController', function($scope, $rootScope) {
	var scenarioSelection = {};
	$scope.setSize = function(event, data) {
		scenarioSelection.size = data;
		event.preventDefault();
	};

	$scope.setShape = function(event, data) {
		scenarioSelection.shape = data;
		event.preventDefault();
	};

	$scope.export = function(event) {
		window.print();
		event.preventDefault();
	}
	angular.element(document).ready(function() {

		$(".size-content").css({
			display : "none"
		});
		$(".shape-content").css({
			display : "none"
		});

		$(".size").click(function(event) {
			$(".size-content").slideToggle("slow");
			event.preventDefault();
		});

		$(".shape").click(function(event) {
			$(".shape-content").slideToggle("slow");
			event.preventDefault();
		});

		$(".size-content a").click(function(event) {
			scenarioSelection.description = "Diseño escenario";
			$rootScope.scenario = scenarioSelection;
			$(this).closest("ul").slideUp("slow");
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
			event.preventDefault();
		});

		$(".shape-content a").click(function(event) {
			scenarioSelection.description = "Diseño escenario";
			$rootScope.scenario = scenarioSelection;
			$(this).closest("ul").slideUp("slow");
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
			event.preventDefault();
		});

	});
});
MyTechRiderApp.controller('BackLineController', function($scope, $rootScope) {
	var scenarioSelection = {};
	var rootBackStage = $rootScope.backstage;
	$scope.setSize = function(event, data) {
		scenarioSelection.size = data;
		event.preventDefault();
	};

	$scope.setShape = function(event, data) {
		scenarioSelection.shape = data;
		event.preventDefault();
	};

	$scope.export = function(event) {
		window.print();
		event.preventDefault();
	}

	angular.element(document).ready(function() {

		$(".size-content").css({
			display : "none"
		});
		$(".shape-content").css({
			display : "none"
		});

		$(".size").click(function(event) {
			$(".size-content").slideToggle("slow");
			event.preventDefault();
		});

		$(".shape").click(function(event) {
			$(".shape-content").slideToggle("slow");
			event.preventDefault();
		});

		$(".size-content a").click(function(event) {
			scenarioSelection.description = "Diseño escenario";
			$rootScope.scenario = scenarioSelection;
			$(this).closest("ul").slideUp("slow");
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
			event.preventDefault();

		});

		$(".shape-content a").click(function(event) {
			scenarioSelection.description = "Diseño escenario";
			$rootScope.scenario = scenarioSelection;
			$(this).closest("ul").slideUp("slow");
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
			event.preventDefault();
		});

	});
});
MyTechRiderApp.controller('VoiceController', function($scope, $rootScope) {
	var currSesion = false;
	var voiceConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.voice;

	var voiceSelection = {};
	voiceSelection.type = "Vocalista";

	$scope.voiceOptions = {
		type : voiceConfig.type.options,
		mic : voiceConfig.mic.options
	}
	$scope.setType = function(event, data) {
		voiceSelection.type = data;
		event.preventDefault();
	}

	$scope.setPosition = function(event, data) {
		voiceSelection.position = data;
		event.preventDefault();
	}

	$scope.setMic = function(event, data) {
		voiceSelection.mic = data;
		event.preventDefault();
	}

	$scope.isSelected = function(type) {
		return voiceSelection === type;
	}

	$scope.save = function(event) {
		if (voiceSelection.type === "Vocalista") {
			voiceSelection.description = "Voz";
			voiceSelection.thumb = "voz1.png";
			voiceSelection.class = "voz";
		} else {
			voiceSelection.description = "Coro";
			voiceSelection.thumb = "cor1.png";
			voiceSelection.class = "cor";
		}

		voiceSelection.channel = $scope.channel;
		voiceSelection.artistName = $scope.artistName;
		if (currSesion == false) {
			$rootScope.backstage.voice.push(voiceSelection);
			$rootScope.backstage.channels[$scope.channel - 1] = voiceSelection;
			currSesion = true;
		} else {
			var numPosArr = $rootScope.backstage.voice.length;
			$rootScope.backstage.voice[numPosArr - 1] = voiceSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = voiceSelection;
		}

		if ($rootScope.backstage.positions[voiceSelection.position] === undefined) {
			$rootScope.backstage.positions[voiceSelection.position] = [{
				position : voiceSelection.position,
				description : voiceSelection.description,
				thumb : voiceSelection.thumb,
				class : voiceSelection.class
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[voiceSelection.position];
			tempArr.push({
				position : voiceSelection.position,
				description : voiceSelection.description,
				thumb : voiceSelection.thumb,
				class : voiceSelection.class
			});
			$rootScope.backstage.positions[voiceSelection.position] = tempArr;
		}
		console.log(voiceSelection);
		event.preventDefault();
	};

	angular.element(document).ready(function() {

		$("#typeControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});

		$("#micControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});

		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});
MyTechRiderApp.controller('AcusticGuitarController', function($scope, $rootScope) {
	var acusticGuitarSelection = {};
	var currSesion = false;
	$scope.setPosition = function(event, data) {
		acusticGuitarSelection.position = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		acusticGuitarSelection.description = "Guitarra acústica";
		acusticGuitarSelection.channel = $scope.channel;
		acusticGuitarSelection.artistName = $scope.artistName;
		acusticGuitarSelection.directBox = $scope.directBox;
		acusticGuitarSelection.thumb = "acu1.png";
		console.log(acusticGuitarSelection);

		if (currSesion == false) {
			$rootScope.backstage.acusticGuitar.push(acusticGuitarSelection);
			$rootScope.backstage.channels[$scope.channel - 1] = (acusticGuitarSelection);
			currSesion = true;
		} else {
			var numPosArr = $rootScope.backstage.acusticGuitar.length;
			$rootScope.backstage.acusticGuitar[numPosArr - 1] = acusticGuitarSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = acusticGuitarSelection;
		}

		if ($rootScope.backstage.positions[acusticGuitarSelection.position] === undefined) {
			$rootScope.backstage.positions[acusticGuitarSelection.position] = [{
				position : acusticGuitarSelection.position,
				description : acusticGuitarSelection.description,
				thumb : acusticGuitarSelection.thumb,
				class : "acu"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[acusticGuitarSelection.position];
			tempArr.push({
				position : acusticGuitarSelection.position,
				description : acusticGuitarSelection.description,
				thumb : acusticGuitarSelection.thumb,
				class : "acu"
			});
			$rootScope.backstage.positions[acusticGuitarSelection.position] = tempArr;
		}
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});
MyTechRiderApp.controller('ElectricGuitarController', function($scope, $rootScope) {
	var electricGuitarConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.electricguitar;
	var electricGuitarSelection = {};
	var currSesion = false;

	$scope.electricGuitarOptions = {
		mic : electricGuitarConfig.mic.options,
		amplifier : electricGuitarConfig.amplifier.brands.options
	}
	$scope.setPosition = function(event, data) {
		electricGuitarSelection.position = data;
		event.preventDefault();
	}
	$scope.setAmp = function(event, dataName, dataType) {
		electricGuitarSelection.amp = {
			name : dataName,
			type : dataType
		}
		event.preventDefault();
	}
	$scope.setMic = function(event, data) {
		electricGuitarSelection.mic = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		electricGuitarSelection.description = "Guitarra Eléctrica";
		electricGuitarSelection.channel = $scope.channel;
		electricGuitarSelection.artistName = $scope.artistName;
		electricGuitarSelection.directBox = $scope.directBox;
		electricGuitarSelection.thumb = "ele1.png";
		electricGuitarSelection.otro = $scope.otro;
		console.log(electricGuitarSelection);

		if (currSesion == false) {
			$rootScope.backstage.electricGuitar.push(electricGuitarSelection);
			$rootScope.backstage.channels[$scope.channel - 1] = (electricGuitarSelection);
			currSesion = true;
		} else {
			var numPosArr = $rootScope.backstage.electricGuitar.length;
			$rootScope.backstage.electricGuitar[numPosArr - 1] = electricGuitarSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = electricGuitarSelection;
		}

		if ($rootScope.backstage.positions[electricGuitarSelection.position] === undefined) {
			$rootScope.backstage.positions[electricGuitarSelection.position] = [{
				position : electricGuitarSelection.position,
				description : electricGuitarSelection.description,
				thumb : electricGuitarSelection.thumb,
				class : "ele"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[electricGuitarSelection.position];
			tempArr.push({
				position : electricGuitarSelection.position,
				description : electricGuitarSelection.description,
				thumb : electricGuitarSelection.thumb,
				class : "ele"
			});
			$rootScope.backstage.positions[electricGuitarSelection.position] = tempArr;
		}
		// $rootScope.inputList.electricGuitarSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$('.bxslider').bxSlider({
			infiniteLoop : true,
			hideControlOnEnd : true,
			easing : 'easeOutBounce',
			infiniteLoop : false,
			speed : 400
		});
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});

		$("#micControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#ampControl a").click(function() {
			$(this).closest(".bxslider").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('DrumController', function($scope, $rootScope) {
	var drumConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.drums;
	var drumSelection = {};
	drumSelection.drumParts = {}, j = 0;
	var currSesion = false;
	$scope.channel = [];

	drumSelection.set = "Set 1 (2 toms)";
	console.log($scope.channel);
	$scope.drumOptions = {
		set : drumConfig.set.options,
		brand : drumConfig.brand.options,
		micParts : drumConfig.mic.parts
	}
	$scope.setPosition = function(event, data) {
		drumSelection.position = data;
		event.preventDefault();
	}
	$scope.setSet = function(event, data) {
		drumSelection.set = data;
		event.preventDefault();
	}
	$scope.setBrand = function(event, data) {
		drumSelection.brand = data;
		event.preventDefault();
	}
	$scope.setConfigMic = function(event, reference, part, channel, index) {

		drumSelection.drumParts[index] = {
			description : part,
			mic : reference,
			reference : reference,
			channel : channel
		}
		event.preventDefault();
	}

	var listAvailableChannels = $scope.getListAvailableChannels();

	$scope.change = function(pAction, pIndex) {
		console.log(pIndex);
		if (pAction === "add") {
			j++;
		} else {
			j--;
		}
		console.log($scope.channel[pIndex]);
		console.log(listAvailableChannels[j].channel);
		$scope.channel[pIndex] = listAvailableChannels[j].channel;
	};

	$scope.getFirstAvailableChannel = function(pIndex){
		$scope.channel[pIndex] = listAvailableChannels[0].channel;
		return 	$scope.channel[pIndex];
	}

	$scope.updateDataListChannel = function (event){
		var lengthArr = listAvailableChannels.length;
		var lastDataPos = listAvailableChannels[lengthArr-1];
		console.log(j);
		listAvailableChannels[j] = lastDataPos;
		listAvailableChannels.pop();
		listAvailableChannels.sort(function (a, b) { 
		    return a.channel - b.channel;
		});

		$scope.getFirstAvailableChannel();
	}

	$scope.save = function(event) {
		//drumSelection.channel = $scope.channel;
		drumSelection.description = "Batería";
		drumSelection.artistName = $scope.artistName;
		// drumSelection.directBox = $scope.directBox;
		drumSelection.thumb = "bat1.png";
		drumSelection.serie = $scope.serie;
		// $rootScope.backstage.drum = drumSelection;

		if (currSesion == false) {
			$rootScope.backstage.drum.push(drumSelection);
			var k = 0;
			for (var key in drumSelection.drumParts) {
				console.log(drumSelection.drumParts[key]);
				$rootScope.backstage.drum.push(drumSelection.drumParts[key]);
				console.log($scope.channel[k]);
				console.log(k);
				$rootScope.backstage.channels[$scope.channel[k]-1] = (drumSelection.drumParts[key]);
				k++;
			}

			currSesion = true;
		} else {
			var numPosArr = $rootScope.backstage.drum.length;
			$rootScope.backstage.drum[numPosArr - 1] = drumSelection;
			numPosArr = $rootScope.backstage.channels.length;
			var k = 0;
			for (var key in drumSelection.drumParts) {
				$rootScope.backstage.channels[$scope.channel[k]-1] = (drumSelection.drumParts[key]);
			}
			k++;
		}
		if ($rootScope.backstage.positions[drumSelection.position] === undefined) {
			$rootScope.backstage.positions[drumSelection.position] = [{
				position : drumSelection.position,
				description : drumSelection.description,
				thumb : drumSelection.thumb,
				class : "bat"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[drumSelection.position];
			tempArr.push({
				position : drumSelection.position,
				description : drumSelection.description,
				thumb : drumSelection.thumb,
				class : "bat"
			});
			$rootScope.backstage.positions[drumSelection.position] = tempArr;
		}
		console.log(drumSelection);
		// $rootScope.inputList.drumSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$('.bxslider').bxSlider({
			infiniteLoop : true,
			hideControlOnEnd : true,
			easing : 'easeOutBounce',
			infiniteLoop : false,
			speed : 400
		});

		$("#brandControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#setControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#partsControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#micControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#ampControl a").click(function() {
			$(this).closest(".bxslider").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('BassController', function($scope, $rootScope) {
	var bassConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.bass;
	var bassSelection = {};
	var currSesion = false;

	$scope.bassOptions = {
		mic : bassConfig.mic.options,
		amplifier : bassConfig.amplifier.options
	}
	$scope.setPosition = function(event, data) {
		bassSelection.position = data;
		event.preventDefault();
	}
	$scope.setAmp = function(event, data) {
		bassSelection.amp = data;
		event.preventDefault();
	}
	$scope.setMic = function(event, data) {
		bassSelection.mic = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		bassSelection.description = "Bajo";
		bassSelection.channel = $scope.channel;
		bassSelection.directBox = $scope.directBox;
		bassSelection.artistName = $scope.artistName;
		bassSelection.thumb = "baj1.png";
		bassSelection.serie = $scope.serie;

		if (currSesion == false) {
			$rootScope.backstage.bass.push(bassSelection);
			$rootScope.backstage.channels[$scope.channel - 1] = (bassSelection);
			currSesion = true;
		} else {
			var numPosArr = $rootScope.bass.bassSelection.length;
			$rootScope.backstage.bass[numPosArr - 1] = bassSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = bassSelection;
		}
		if ($rootScope.backstage.positions[bassSelection.position] === undefined) {
			$rootScope.backstage.positions[bassSelection.position] = [{
				position : bassSelection.position,
				description : bassSelection.description,
				thumb : bassSelection.thumb,
				class : "baj"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[bassSelection.position];
			tempArr.push({
				position : bassSelection.position,
				description : bassSelection.description,
				thumb : bassSelection.thumb,
				class : "baj"
			});
			$rootScope.backstage.positions[bassSelection.position] = tempArr;
		}
		console.log(bassSelection);
		// $rootScope.inputList.bassSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#micControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#ampControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('PianoController', function($scope, $rootScope) {
	var pianoConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.piano;
	var pianoSelection = {};
	var currSesion = false;

	$scope.pianoOptions = {
		mic : pianoConfig.mic.options,
		brand : pianoConfig.brand.options
	}
	$scope.setPosition = function(event, data) {
		pianoSelection.position = data;
		event.preventDefault();
	}
	$scope.setMic = function(event, data) {
		pianoSelection.mic = data;
		event.preventDefault();
	}
	$scope.setBrand = function(event, data) {
		pianoSelection.brand = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		pianoSelection.description = "Piano";
		pianoSelection.channel = $scope.channel;
		pianoSelection.directBox = $scope.directBox;
		pianoSelection.artistName = $scope.artistName;
		pianoSelection.thumb = "pia1.png";

		if (currSesion == false) {
			$rootScope.backstage.piano.push(pianoSelection);
			$rootScope.backstage.channels[$scope.channel - 1] = (pianoSelection);
			currSesion = true;
		} else {
			var numPosArr = $rootScope.piano.pianoSelection.length;
			$rootScope.backstage.piano[numPosArr - 1] = pianoSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = pianoSelection;
		}

		if ($rootScope.backstage.positions[pianoSelection.position] === undefined) {
			$rootScope.backstage.positions[pianoSelection.position] = [{
				position : pianoSelection.position,
				description : pianoSelection.description,
				thumb : pianoSelection.thumb,
				class : "pia"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[pianoSelection.position];
			tempArr.push({
				position : pianoSelection.position,
				description : pianoSelection.description,
				thumb : pianoSelection.thumb,
				class : "pia"
			});
			$rootScope.backstage.positions[pianoSelection.position] = tempArr;
		}
		console.log(pianoSelection);
		// $rootScope.inputList.pianoSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#brandControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#micControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('KeyboardController', function($scope, $rootScope) {
	var keyboardConfig = $rootScope.RiderConfigData.MyRiderOptions.backline.keyboard;
	var keyboardSelection = {};
	var currSesion = false;

	$scope.keyboardOptions = {
		brand : keyboardConfig.brand.options
	}
	$scope.setPosition = function(event, data) {
		keyboardSelection.position = data;
		event.preventDefault();
	}
	$scope.setBrand = function(event, data) {
		keyboardSelection.brand = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		keyboardSelection.description = "Keyboard";
		keyboardSelection.channel = $scope.channel;
		keyboardSelection.directBox = $scope.directBox;
		keyboardSelection.artistName = $scope.artistName;
		keyboardSelection.thumb = "key1.png";
		keyboardSelection.serie = $scope.serie;

		if (currSesion == false) {
			$rootScope.backstage.keyboard.push(keyboardSelection);
			$rootScope.backstage.channels[$scope.channel - 1] =(keyboardSelection)
			currSesion = true;
		} else {
			var numPosArr = $rootScope.keyboard.keyboardSelection.length;
			$rootScope.backstage.keyboard[numPosArr - 1] = keyboardSelection;
			numPosArr = $rootScope.backstage.channels.length;
			$rootScope.backstage.channels[numPosArr - 1] = keyboardSelection;
		}
		console.log(keyboardSelection);

		if ($rootScope.backstage.positions[keyboardSelection.position] === undefined) {
			$rootScope.backstage.positions[keyboardSelection.position] = [{
				position : keyboardSelection.position,
				description : keyboardSelection.description,
				thumb : keyboardSelection.thumb,
				class : "key"
			}];
		} else {
			var tempArr = $rootScope.backstage.positions[keyboardSelection.position];
			tempArr.push({
				position : keyboardSelection.position,
				description : keyboardSelection.description,
				thumb : keyboardSelection.thumb,
				class : "key"
			});
			$rootScope.backstage.positions[keyboardSelection.position] = tempArr;
		}
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#positionControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#brandControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('PaController', function($scope, $rootScope) {
	var paConfig = $rootScope.RiderConfigData.MyRiderOptions.audio.pa;
	var paSelection = {};
	paSelection.category = [];
	$scope.paOptions = {
		brand : paConfig.brand.options,
		category : paConfig.category.options
	}
	$scope.setCategory = function(event, data, index) {
		if(paSelection.category[index] === undefined){
			paSelection.category[index] = data;
		}else{
			delete paSelection.category[index];
		}
		
		event.preventDefault();
	}
	$scope.setBrand = function(event, data) {
		paSelection.brand = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		console.log(paSelection);
		paSelection.description = "PA";
		paSelection.serie = $scope.serie;
		$rootScope.pa = paSelection;
		// $rootScope.inputList.paSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#categoryControl a").click(function() {
			$(this).toggleClass("selected");
		});
		$("#brandControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('FohController', function($scope, $rootScope) {
	var fohConfig = $rootScope.RiderConfigData.MyRiderOptions.audio.foh;
	var fohSelection = {};

	$scope.fohOptions = {
		channel : fohConfig.channels.options,
		brand : fohConfig.brand.options
	}
	$scope.setChannel = function(event, data) {
		fohSelection.channel = data;
		event.preventDefault();
	}
	$scope.setBrand = function(event, data) {
		fohSelection.brand = data;
		event.preventDefault();
	}
	$scope.save = function(event) {
		console.log(fohSelection);
		fohSelection.description = "FOH";
		fohSelection.serie = $scope.serie;
		$rootScope.foh = fohSelection;
		// $rootScope.inputList.fohSelection
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#channelControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#brandControl a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});
MyTechRiderApp.filter('slice', function() {
	return function(arr, start, end) {
		return arr.slice(start, end);
	};
});

MyTechRiderApp.filter('offset', function() {
	return function(input, start) {
		start = parseInt(start, 10);
		return input.slice(start);
	};
});
MyTechRiderApp.controller('MonitorsController', function($scope, $rootScope) {
	var monitorsSelection = {};
	monitorsSelection.brandA = [];
	monitorsSelection.brandB = [];
	monitorsSelection.consoleA = [];
	monitorsSelection.channelA = [];
	monitorsSelection.categoryA = [];

	$scope.setCategoryA = function(event, data, index) {
		console.log(index);
		console.log(data);
		if(monitorsSelection.categoryA[index] === undefined){
			monitorsSelection.categoryA[index] = data;
		}else{
			delete monitorsSelection.categoryA[index];
			console.log( monitorsSelection.categoryA[index]);
		}
		event.preventDefault();
	}
	$scope.setCategoryB = function(event, data) {
		monitorsSelection.categoryB = data;
		event.preventDefault();
	}
	$scope.setBrandA = function(event, data) {
		monitorsSelection.brandA.push(data);
		event.preventDefault();
	}
	$scope.setBrandB = function(event, data) {
		monitorsSelection.brandB.push(data);
		event.preventDefault();
	}

	$scope.setConsoleA = function(event, data) {
		monitorsSelection.consoleA.push(data);
		event.preventDefault();
	}

	$scope.setChannelA = function(event, data) {
		monitorsSelection.channelA.push(data);
		event.preventDefault();
	}
	$scope.save = function(event) {
		console.log(monitorsSelection);
		monitorsSelection.description = "Monitor System";
		$rootScope.monitors = monitorsSelection;
		event.preventDefault();
	};
	angular.element(document).ready(function() {
		$("#categoryControlA a").click(function() {
			$(this).toggleClass("selected");
		});
		$("#categoryControlB a").click(function() {
			$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#brandControlA a").click(function() {
			//$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
		$("#brandControlB a").click(function() {
			//$(this).closest("ul").find(".selected").removeClass("selected");
			$(this).addClass("selected");
		});
	});
});

MyTechRiderApp.controller('InputListController', function($scope, $rootScope) {
	$scope.number = 20;
    $scope.getNumber = function(num) {
        return new Array(num);   
    }
	$scope.save = function(event) {
		$rootScope.backstage.channels = $scope.backstage.channels;
		$rootScope.auxMonitor = $scope.auxMonitor;
		console.log($scope.auxMonitor);
		event.preventDefault();
	};
});

MyTechRiderApp.controller('CreditosController', function($scope, $rootScope) {
});

MyTechRiderApp.controller('TemplatesController', function($scope, $rootScope) {
});

